package com.heima.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApArticleServiceImpl extends ServiceImpl<ApArticleMapper, ApArticle> implements ApArticleService {

    @Autowired
    private ApArticleMapper apArticleMapper;

    @Override
    public ResponseResult<PageResponseResult> list(Integer channelId, Integer page, Integer size) {
        Long total = apArticleMapper.count(channelId);
        int start = ( page - 1 ) * size;
        List<ApArticle> apArticleList = apArticleMapper.selectByPage(channelId , start , size);
        return new PageResponseResult(page , size , total.intValue() , apArticleList);
    }
}
